package com.wang.mandkey.activity;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.LinearLayout;

import com.wang.mandkey.R;
import com.wang.mandkey.views.VirtualKeyboard;
import com.wang.mandkey.views.VirtualKeyboard.InterfaceOnclick;

public class VirtualKeyBoardActivity extends BaseActivity implements OnClickListener{
	/** Called when the activity is first created. */

	LinearLayout mExpandedButton;
	Button mButtonOne;
	Button mButtonTwo;
	Button mButtonThree;
	Button mButtonFour;
	Animation translateEntranceAnimation ;
	Animation translateExitAnimation;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.virtualkeyboard);
		
		initView();
		
		buttonOnClicker();
		
		VirtualKeyboard kbd = (VirtualKeyboard) findViewById(R.id.kbd);
		kbd.setInterfaceOnclick(new InterfaceOnclick() {
			@Override
			public void onClick(String buttonText) {
				if (buttonText.equals("++++")) {
					buttonShow();
				}
			}
		});
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.buttonOne:
		case R.id.buttonTwo:
		case R.id.buttonThree:
		case R.id.buttonFour:
//			Toast.makeText(this,"test",Toast.LENGTH_SHORT).show();
			expandedButtonExitAnimation();
			break;
			
		default:
			break;
		}
		
	}
	
	public void initView(){
		mExpandedButton = (LinearLayout) findViewById(R.id.linearlayoutExpand);
		mButtonOne = (Button) findViewById(R.id.buttonOne);
		mButtonTwo = (Button) findViewById(R.id.buttonTwo);
	    mButtonThree=(Button) findViewById(R.id.buttonThree);
		mButtonFour = (Button) findViewById(R.id.buttonFour);
		translateEntranceAnimation=AnimationUtils.loadAnimation(VirtualKeyBoardActivity.this, R.anim.slide_in_right);
		translateExitAnimation=AnimationUtils.loadAnimation(VirtualKeyBoardActivity.this, R.anim.slide_out_right);
		
	}
	

	
	public void buttonOnClicker(){
		mButtonOne.setOnClickListener(this);
		mButtonTwo.setOnClickListener(this);
		mButtonThree.setOnClickListener(this);
		mButtonFour.setOnClickListener(this);
	}
	
	public void buttonShow(){
		mExpandedButton.setVisibility(View.VISIBLE);
		mExpandedButton.startAnimation(translateEntranceAnimation);
		mButtonOne.setText(R.string.virtualkeyboard_top);
		mButtonTwo.setText(R.string.virtualkeyboard_bottom);
		mButtonThree.setText(R.string.virtualkeyboard_left);
		mButtonFour.setText(R.string.virtualkeyboard_right);
	}
	
	public void expandedButtonExitAnimation(){
		mExpandedButton.startAnimation(translateExitAnimation);
		translateExitAnimation.setAnimationListener(new AnimationListener() {
			

			@Override
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				mExpandedButton.setVisibility(View.GONE);
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				
			}
		});
	}
	

}